//
//  XHMyCouponsViewController.m
//  umibus
//
//  Created by 冷山 on 16/6/17.
//  Copyright © 2016年 lexingsoft. All rights reserved.
//

#import "XHMyCouponsViewController.h"
#import "XHSellCouponsViewController.h"
#import "XHShareViewController.h"
#import "XHTabBarController.h"

#import "XHCouponsCell.h"

#import "Services.h"
#import "AppDelegate.h"

#import <SVPullToRefresh/SVPullToRefresh.h>

static const NSUInteger kPageSize = 20;
static const NSUInteger kPageInit = 0;


@interface XHMyCouponsViewController ()<XHCouponsCellDelegate>
@property (weak, nonatomic) IBOutlet UITableView *ui_tableView;
@property (strong, nonatomic) NSMutableArray * m_couposArr;
@property (assign, nonatomic) NSUInteger page;
@property (assign, nonatomic) BOOL hasNextPage;

@end

@implementation XHMyCouponsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.ui_tableView registerNib:[UINib nibWithNibName:@"XHCouponsCell" bundle:nil] forCellReuseIdentifier:XHCouponsCellIdentifier];
    
    self.page=kPageInit;
    [self.ui_tableView addInfiniteScrollingWithActionHandler:^{
        if (!self.hasNextPage)
        {
            //[PromptAction showErrorPrompt:@"暂无更多数据"];
        }
        if (self.m_couposArr.count>=kPageSize){
            [self getUserConpons:self.page+1];
            return;
        }
        [self.ui_tableView.infiniteScrollingView stopAnimating];
    }];
    [self.ui_tableView addPullToRefreshWithActionHandler:^{
        self.page=kPageInit;
        [self getUserConpons:self.page];
    }];
    [PublicMethod setPullToRefreshView:self.ui_tableView];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.page = kPageInit;
    [self getUserConpons:self.page];
}

- (void)getUserConpons:(NSUInteger)page
{
    [ServiceManager getUserCouponWithPageIndex:page success:^(NSDictionary *data) {
        if (page == kPageInit || self.m_couposArr == nil)
        {
            self.m_couposArr = [NSMutableArray array];
        }
        NSArray * datas=data[@"result"];
        self.hasNextPage=(datas.count==kPageSize);
        if (datas.count>0)
        {
            self.page = page;
            [self.m_couposArr addObjectsFromArray:datas];
        }
        [self.ui_tableView reloadData];
        [self.ui_tableView.infiniteScrollingView stopAnimating];
        [PublicMethod setFinishRefreshView:self.ui_tableView];
        [self performSelector:@selector(stopAnimate:) withObject:nil afterDelay:2.0];
        [self setNothingViewIsHide:self.m_couposArr.count!=0];
    } failure:^(NSDictionary *data) {
        [self.ui_tableView.infiniteScrollingView stopAnimating];
        [self.ui_tableView.pullToRefreshView stopAnimating];
        [self setNothingViewIsHide:self.m_couposArr.count!=0];
        
    }];
}
- (void)stopAnimate:(NSTimer*)timer
{
    [self.ui_tableView.pullToRefreshView stopAnimating];
    [PublicMethod setPullToRefreshView:self.ui_tableView];
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSUInteger rows=0;
    rows = self.m_couposArr.count;
    return rows;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    cell = [self couponsCell:indexPath];
    return cell;
}

- (XHCouponsCell*)couponsCell:(NSIndexPath*)indexPath
{
    XHCouponsCell * cell = [self.ui_tableView dequeueReusableCellWithIdentifier:XHCouponsCellIdentifier];
    cell.delegate = self;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSDictionary * dic = self.m_couposArr[indexPath.row];
    cell.ui_sellButton.tag = indexPath.row;
    cell.ui_useButton.tag = indexPath.row;
    cell.ui_examplesButton.tag = indexPath.row;
    cell.ui_couponsContent.text = [NSString stringWithFormat:@"满%@元可用",dic[@"minOrderAmount"]];
    [cell setCouponsUsedType:dic];
    if([dic[@"couponType"]isEqualToString:@"VOUCHER_TICKET"])
    {
        //代金券
        cell.ui_discountView.hidden = YES;
        cell.ui_leftlabel.hidden = NO;
        cell.ui_rightLabel.hidden = NO;
        cell.ui_leftlabel.text = @"￥";
        cell.ui_leftlabel.font = [UIFont systemFontOfSize:25];
        cell.ui_rightLabel.font = [UIFont systemFontOfSize:50];
        NSString * money = [NSString stringWithFormat:@"%.2f",[dic[@"couponValue"] doubleValue]];
        NSString * lastOne = [money substringWithRange:NSMakeRange(money.length-1,1)];
        NSString * lastTwo = [money substringWithRange:NSMakeRange(money.length-2,1)];
        if ([lastOne doubleValue]==0&&
            [lastTwo doubleValue]==0)
        {
            cell.ui_rightLabel.text = [NSString stringWithFormat:@"%@",dic[@"couponValue"]];
        }
        else if ([lastOne doubleValue]==0&&
                 [lastTwo doubleValue]!=0)
        {
            cell.ui_rightLabel.text = [NSString stringWithFormat:@"%.1f",[dic[@"couponValue"] doubleValue]];
        }
        else if ([lastOne doubleValue]!=0&&
                 [lastTwo doubleValue]!=0)
        {
            cell.ui_rightLabel.text = [NSString stringWithFormat:@"%.2f",[dic[@"couponValue"] doubleValue]];
        }
        NSString * startTime = [[NSDate dateWithString:dic[@"startTime"]] stringSlashWithFormatter];
        NSString * endTime = [[NSDate dateWithString:dic[@"endTime"]] stringSlashWithFormatter];
        cell.ui_useTime.text = [NSString stringWithFormat:@"%@ - %@",startTime,endTime];
        if ([dic[@"operatorCode"]isEqualToString:@"10086"])
        {
            if([dic[@"couponStatus"]isEqualToString:@"USED"]||
               [dic[@"expires"] isEqualToString:@"Y"])
            {
                cell.ui_useButton.hidden = YES;
                cell.ui_sellButton.hidden = YES;
                cell.ui_examplesButton.hidden = YES;
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_bukeyong"];
                cell.ui_leftlabel.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_rightLabel.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_useConut.text = [NSString stringWithFormat:@"可使用次数:0次"];
                if ([dic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"代金券-移动话费直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"代金券-移动智能缴费";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"代金券-移动流量直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"代金券-移动流量屯包";
                }
            }
            else
            {
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_yidong"];
                cell.ui_leftlabel.textColor = [ColorManager colorWithHexString:@"#59A46C"];
                cell.ui_rightLabel.textColor = [ColorManager colorWithHexString:@"#59A46C"];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#59A46C"];
                cell.ui_useConut.text = [NSString stringWithFormat:@"可使用次数:1次"];
                if ([dic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"代金券-移动话费直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"代金券-移动智能缴费";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"代金券-移动流量直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"代金券-移动流量屯包";
                }
            }
        }
        else if ([dic[@"operatorCode"]isEqualToString:@"10010"])
        {
            if([dic[@"couponStatus"]isEqualToString:@"USED"]||
               [dic[@"expires"] isEqualToString:@"Y"])
            {
                cell.ui_useButton.hidden = YES;
                cell.ui_sellButton.hidden = YES;
                cell.ui_examplesButton.hidden = YES;
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_bukeyong"];
                cell.ui_leftlabel.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_rightLabel.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_useConut.text = [NSString stringWithFormat:@"可使用次数:0次"];
                if ([dic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"代金券-联通话费直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"代金券-联通智能缴费";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"代金券-联通流量直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"代金券-联通流量屯包";
                }
            }
            else
            {
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_liantong"];
                cell.ui_leftlabel.textColor = [ColorManager colorWithHexString:@"#E45252"];
                cell.ui_rightLabel.textColor = [ColorManager colorWithHexString:@"#E45252"];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#E45252"];
                cell.ui_useConut.text = [NSString stringWithFormat:@"可使用次数:1次"];
                if ([dic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"代金券-联通话费直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"代金券-联通智能缴费";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"代金券-联通流量直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"代金券-联通流量屯包";
                }
            }
        }
        else if ([dic[@"operatorCode"]isEqualToString:@"10000"])
        {
            if([dic[@"couponStatus"]isEqualToString:@"USED"]||
               [dic[@"expires"] isEqualToString:@"Y"])
            {
                cell.ui_useButton.hidden = YES;
                cell.ui_sellButton.hidden = YES;
                cell.ui_examplesButton.hidden = YES;
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_bukeyong"];
                cell.ui_leftlabel.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_rightLabel.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_useConut.text = [NSString stringWithFormat:@"可使用次数:0次"];
                if ([dic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"代金券-电信话费直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"代金券-电信智能缴费";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"代金券-电信流量直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"代金券-电信流量屯包";
                }
            }
            else
            {
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_dianxin"];
                cell.ui_leftlabel.textColor = [ColorManager colorWithHexString:@"#00AED2"];
                cell.ui_rightLabel.textColor = [ColorManager colorWithHexString:@"#00AED2"];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#00AED2"];
                cell.ui_useConut.text = [NSString stringWithFormat:@"可使用次数:1次"];
                if ([dic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"代金券-电信话费直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"代金券-电信智能缴费";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"代金券-电信流量直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"代金券-电信流量屯包";
                }
            }
        }
    }
    else if ([dic[@"couponType"]isEqualToString:@"DISCOUNT_TICKET"])
    {
        //折扣
        cell.ui_discountView.hidden = NO;
        cell.ui_leftlabel.hidden = YES;
        cell.ui_rightLabel.hidden = YES;
        NSString * str = [NSString stringWithFormat:@"%.1f",[dic[@"couponValue"] doubleValue]];
        NSString * lastOne = [str substringFromIndex:str.length-1];
        if ([lastOne isEqualToString:@"0"])
        {
            cell.ui_zhe.text = [NSString stringWithFormat:@"%@",dic[@"couponValue"]];
        }
        else
        {
            cell.ui_zhe.text = [NSString stringWithFormat:@"%@",str];
        }
        NSString * startTime = [[NSDate dateWithString:dic[@"startTime"]] stringSlashWithFormatter];
        NSString * endTime = [[NSDate dateWithString:dic[@"endTime"]] stringSlashWithFormatter];
        cell.ui_useTime.text = [NSString stringWithFormat:@"%@ - %@",startTime,endTime];
        if ([dic[@"operatorCode"]isEqualToString:@"10086"])
        {
            if([dic[@"couponStatus"]isEqualToString:@"USED"]||
               [dic[@"expires"] isEqualToString:@"Y"])
            {
                cell.ui_useButton.hidden = YES;
                cell.ui_sellButton.hidden = YES;
                cell.ui_examplesButton.hidden = YES;
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_bukeyong"];
                cell.ui_zhe.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_zheLabel.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_useConut.text = [NSString stringWithFormat:@"可使用次数:0次"];
                if ([dic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"抵扣券-移动话费直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"抵扣券-移动智能缴费";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"抵扣券-移动流量直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"抵扣券-移动流量屯包";
                }
            }
            else
            {
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_yidong"];
                cell.ui_zhe.textColor = [ColorManager colorWithHexString:@"#59A46C"];
                cell.ui_zheLabel.textColor = [ColorManager colorWithHexString:@"#59A46C"];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#59A46C"];
                cell.ui_useConut.text = [NSString stringWithFormat:@"可使用次数:1次"];
                if ([dic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"抵扣券-移动话费直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"抵扣券-移动智能缴费";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"抵扣券-移动流量直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"抵扣券-移动流量屯包";
                }
            }
        }
        else if ([dic[@"operatorCode"]isEqualToString:@"10010"])
        {
            if([dic[@"couponStatus"]isEqualToString:@"USED"]||
               [dic[@"expires"] isEqualToString:@"Y"])
            {
                cell.ui_useButton.hidden = YES;
                cell.ui_sellButton.hidden = YES;
                cell.ui_examplesButton.hidden = YES;
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_bukeyong"];
                cell.ui_zhe.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_zheLabel.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_useConut.text = [NSString stringWithFormat:@"可使用次数:0次"];
                if ([dic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"抵扣券-联通话费直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"抵扣券-联通智能缴费";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"抵扣券-联通流量直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"抵扣券-联通流量屯包";
                }
            }
            else
            {
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_liantong"];
                cell.ui_zhe.textColor = [ColorManager colorWithHexString:@"#E45252"];
                cell.ui_zheLabel.textColor = [ColorManager colorWithHexString:@"#E45252"];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#E45252"];
                cell.ui_useConut.text = [NSString stringWithFormat:@"可使用次数:1次"];
                if ([dic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"抵扣券-联通话费直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"抵扣券-联通智能缴费";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"抵扣券-联通流量直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"抵扣券-联通流量屯包";
                }
            }
        }
        else if ([dic[@"operatorCode"]isEqualToString:@"10000"])
        {
            if([dic[@"couponStatus"]isEqualToString:@"USED"]||
               [dic[@"expires"] isEqualToString:@"Y"])
            {
                cell.ui_useButton.hidden = YES;
                cell.ui_sellButton.hidden = YES;
                cell.ui_examplesButton.hidden = YES;
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_bukeyong"];
                cell.ui_zhe.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_zheLabel.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#000000" alpha:0.5];
                cell.ui_useConut.text = [NSString stringWithFormat:@"可使用次数:0次"];
                if ([dic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"抵扣券-电信话费直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"抵扣券-电信智能缴费";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"抵扣券-电信流量直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"抵扣券-电信流量屯包";
                }
            }
            else
            {
                cell.ui_juChi.image = [UIImage imageNamed:@"geren_bg_dianxin"];
                cell.ui_zhe.textColor = [ColorManager colorWithHexString:@"#00AED2"];
                cell.ui_zheLabel.textColor = [ColorManager colorWithHexString:@"#00AED2"];
                cell.ui_couponsType.textColor = [ColorManager colorWithHexString:@"#00AED2"];
                cell.ui_useConut.text = [NSString stringWithFormat:@"可使用次数:1次"];
                if ([dic[@"suitableType"] isEqualToString:@"CALL"])
                {
                    cell.ui_couponsType.text = @"抵扣券-电信话费直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
                {
                    cell.ui_couponsType.text = @"抵扣券-电信智能缴费";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOW"])
                {
                    cell.ui_couponsType.text = @"抵扣券-电信流量直充";
                }
                else if ([dic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
                {
                    cell.ui_couponsType.text = @"抵扣券-电信流量屯包";
                }
            }
        }
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height=158;
    return height;
}

#pragma - mark XHCouponsCellDelegate
//使用
- (void)userAction:(UIButton*)sender
{
    NSDictionary * dic = self.m_couposArr[sender.tag];
    if([dic[@"couponStatus"]isEqualToString:@"USED"])
    {
        
    }
    else
    {
        if ([dic[@"couponStatus"] isEqualToString:@"PUBLISHED"])
        {
            [PromptAction showInfoPrompt:@"该优惠券出售中,下架后方可进行操作"];
            return;
        }
        
        if ([dic[@"suitableType"] isEqualToString:@"CALL"])
        {
            AppDelegate *delegate=[UIApplication sharedApplication].delegate;
            [delegate.tabBarController goViewWithModelName:kBannerTypeHOMEPAGE_HFZC];
            [self.navigationController popToRootViewControllerAnimated:YES];
        }
        else if ([dic[@"suitableType"] isEqualToString:@"INTELLIGENT"])
        {
            AppDelegate *delegate=[UIApplication sharedApplication].delegate;
            [delegate.tabBarController goViewWithModelName:kBannerTypeHOMEPAGE_ZNJF];
            [self.navigationController popToRootViewControllerAnimated:YES];

        }
        else if ([dic[@"suitableType"] isEqualToString:@"FLOW"])
        {
            AppDelegate *delegate=[UIApplication sharedApplication].delegate;
            [delegate.tabBarController goViewWithModelName:kBannerTypeHOMEPAGE_LLZC];
            [self.navigationController popToRootViewControllerAnimated:YES];

        }
        else if ([dic[@"suitableType"] isEqualToString:@"FLOWPACKAGE"])
        {
            AppDelegate *delegate=[UIApplication sharedApplication].delegate;
            [delegate.tabBarController goViewWithModelName:kBannerTypeHOMEPAGE_LLTB];
            [self.navigationController popToRootViewControllerAnimated:YES];

        }
    }
}
//出售
- (void)sellAction:(UIButton*)sender
{
    NSDictionary * dic = self.m_couposArr[sender.tag];
    if([dic[@"couponStatus"]isEqualToString:@"USED"])
    {
        
    }
    else
    {
        if ([dic[@"couponStatus"] isEqualToString:@"PUBLISHED"])
        {
            [PromptAction showInfoPrompt:@"该优惠券出售中,下架后方可进行操作"];
            return;
        }
        XHSellCouponsViewController * viewController = [[XHSellCouponsViewController alloc]init];
        viewController.title = @"出售优惠券";
        viewController.couponsDic = self.m_couposArr[sender.tag];
        [self.navigationController pushViewController:viewController animated:YES];
    }
}
//转赠
- (void)examplesAction:(UIButton*)sender
{
    NSDictionary * dic = self.m_couposArr[sender.tag];
    if([dic[@"couponStatus"]isEqualToString:@"USED"])
    {
        
    }
    else
    {
        if ([dic[@"couponStatus"] isEqualToString:@"PUBLISHED"])
        {
            [PromptAction showInfoPrompt:@"该优惠券出售中,下架后方可进行操作"];
            return;
        }
        NSDictionary * dic = self.m_couposArr[sender.tag];
        XHShareViewController * share = [[XHShareViewController alloc]init];
        share.modalPresentationStyle = UIModalPresentationCustom;
        share.shareType = @"coupons";
        share.sequenceNBR =dic[@"sequenceNBR"];
        [self presentViewController:share animated:NO completion:^{
            
        }];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
